package com.yy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yy.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one=@One(select = "com.yy.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one=@One(select = "com.yy.mapper.ParkingLotMapper.getById")),
            @Result(column = "vehicle_id",property = "vehicle",one=@One(select = "com.yy.mapper.VehicleMapper.getById")),
    })
    @Select("select * from orders join pricing_standard  " +
            "on pricing_standard.id=orders.pricing_standard_id " +
            "join parking_lot on orders.parking_lot_id=parking_lot.id " +
            "join vehicle on orders.vehicle_id=vehicle.id ")
    List<Order> getAll();

    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one=@One(select = "com.yy.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one=@One(select = "com.yy.mapper.ParkingLotMapper.getById")),
            @Result(column = "vehicle_id",property = "vehicle",one=@One(select = "com.yy.mapper.VehicleMapper.getById")),

    })
    @Select("select * from orders join pricing_standard  " +
            "on pricing_standard.id=order.pricing_standard_id " +
            "join parking_lot on orders.parking_lot_id=parking_lot.id " +
            "join vehicle on orders.vehicle_id=vehicle.id " +
            "where orders.id=#{orders.id}")
    Order getById(Long id);

    @Insert("insert into order set in_dateTime=#{inDateTime},out_dateTime=#{outDateTime}" +
            ",price=#{price},is_pay_complete=#{isPayComplete},is_require=#{isRequireInvoicing}" +
            ",parking_lot_id=#{parking.id}" +
            ",pricing_standard_id=#{pricingStandard.id}" +
            ",vehicle_id=#{vehicle.id}")
    int insert(Order entity);
    @Update("update into order set in_dateTime=#{inDateTime},out_dateTime=#{outDateTime}" +
            ",price=#{price},is_pay_complete=#{isPayComplete},is_require=#{isRequireInvoicing}" +
            ",parking_lot_id=#{parking.id}" +
            ",pricing_standard_id=#{pricingStandard.id}" +
            ",vehicle_id=#{vehicle.id}" +
            "where id=#{id}")
    int update(Order entity);
}
